home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / WebObjects / WebObjectsDoc_HTML / DynamicElements / ImagesEx3.wo / ImagesEx3.wos < prev    next >
Encoding:
Text File  |  1996-01-24  |  1.4 KB  |  50 lines

  1. id requestingImage;
  2.  
  3. // This method is invoked just before the page is returned
  4. // to the client. The first time the page is requested, requestingImage is NO 
  5. // so the image isn't put in the response. The browser receives the HTML page
  6. // and then requests the image from the server, which invokes the getImage method.
  7.  
  8. - willGenerateResponse:response inContext:context {
  9.  
  10.     if (requestingImage == YES) {
  11.     [self putImageInResponse:response context:context];
  12.     requestingImage = NO;
  13.     } else {
  14.     // don't put image in response--we're just generating
  15.     // the initial page without the image
  16.     }
  17.     return nil;
  18. }
  19.  
  20.  
  21. // This method sets a flag that informs the willGenerateResponse:inContext:
  22. // method that a request is being made for the image data.
  23. - getImage {
  24.     requestingImage = YES;
  25.     return self;
  26. }
  27.     
  28.  
  29. // This method gets the image data from a file and puts it, along with the
  30. // proper header, into the http response that is set back to the browser.
  31.  
  32. - putImageInResponse:response context:context {
  33.     id theData;
  34.     id theFile;
  35.     id pageName;
  36.     id header = @{"content-type" = "image/gif";};
  37.  
  38.     pageName = [context pageName];
  39.     theFile = [WOApp pathForResource:@"PoweredByNEXTSTEP"  
  40.                 ofType:@"gif" 
  41.             inComponentWithName:pageName];
  42.     if (theFile) {
  43.     theData = [NSData dataWithContentsOfFile:theFile];
  44.     [response setContent:theData];
  45.     [response setHeaders:header];
  46.     }
  47.     return nil;
  48. }
  49.  
  50.